import global from "../global";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Persist extends cc.Component {

    @property(cc.Node)
    Node_tip:cc.Node = null;    //提示信息

    onLoad(){
        global.persist = this;
        cc.game.addPersistRootNode(this.node);
    }

    start(){
        this.Node_tip.active = false;   //先隐藏
    }

    /**
     * 弹出提示信息
     * @param s 
     */
    tip(s:string,is_over:boolean = false){
        if(global.is_replay){
            return;
        }
        this.Node_tip.stopAllActions();
        this.Node_tip.active = true;
        this.Node_tip.getChildByName("desc").getComponent(cc.Label).string = s;
        let action1 = cc.tween().to(.2,{scale:1.2});
        let action2 = cc.tween().to(.1,{scale:1});
        cc.tween(this.Node_tip).sequence(action1,action2).delay(1).call(()=>{
            if(is_over){        //不可解决的错误，提示不关
                cc.game.pause();
            }else{
                this.Node_tip.active = false;
            }
        }).start();
    }

}
